package com.ccrfid.rmc6.ws.c5.videosync;

import com.ccrfid.rmc6.util.JsonUtil;
import com.ccrfid.rmc6.ws.c5.cardreader.pojo.UploadCardRequest;
import com.ccrfid.rmc6.ws.c5.cardreader.pojo.UploadCardResponse;
import com.ccrfid.rmc6.ws.c5.videosync.pojo.ListVideoRequest;
import com.ccrfid.rmc6.ws.c5.videosync.pojo.ListVideoResponse;
import com.ccrfid.rmc6.ws.c5.videosync.pojo.VideoRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;

public class VideoSyncClient extends WebServiceGatewaySupport {
    private static final Logger logger = LoggerFactory.getLogger(VideoSyncClient.class);

    public VideoRes[] listVideo(String serviceUrl, ListVideoRequest request) {
        logger.debug("listVideo request, serviceUrl:{}, requestBody:{}", serviceUrl, request);
        ListVideoResponse response = (ListVideoResponse) getWebServiceTemplate().marshalSendAndReceive(serviceUrl, request);
        logger.debug("listVideo response: {}", response);

        VideoRes[] list = JsonUtil.INSTANCE.readValue(response.getJsonStr(), VideoRes[].class);
        return list;
    }

    public Integer uploadCardRequestTest(String serviceUrl, UploadCardRequest request) {
        logger.debug("uploadCardRequestTest, url:{}, request:{}", serviceUrl, request);
        UploadCardResponse response = (UploadCardResponse) getWebServiceTemplate().marshalSendAndReceive(serviceUrl, request);
        logger.debug("uploadCardRequestTest response: {}", response);
        return response.getRet();
    }
}
